<?php
/*IMPORTANT: 注意检查文件字符集是否为UTF-8*/
/*NOTICE: 使用SOAP功能需要SOAP库支持，请确保在php.ini的extension中已开启了SOAP*/
/**
 *
 * @author Jiong
 * 
 */
class soapstuff
{
	private $wsdl;
	private $header;
	private $elements;
	private $call;
	private $response;
	public function __construct($wsdl,$header,$elements,$call,$response)
	{
		$this->wsdl=$wsdl;
		$this->header=$header;
		$this->elements=$elements;
		$this->call=$call;
		$this->response=$response;
	}
	public function __destruct()
	{
		$this->wsdl = null;
		$this->header = null;
		$this->elements = null;
		$this->call = null;
		$this->response = null;
		unset($this->wsdl);
		unset($this->header);
		unset($this->elements);
		unset($this->call);
		unset($this->response);
	}
	/**
	 *
	 * Data struct & parameters:
	 * $wsdl: string SOAP服务的WSDL路径
	 * $header: array ('namespace'=>string namespace,'name'=>string name,'data'=>mixed data,'mustunderstand'=>bool mustunderstand)
	 * $elements: array (elements)
	 * $call: string 需要调用的服务
	 * $response: string 获取调用服务的返回
	 * 
	 */
	public function setSoap($wsdl,$header,$elements,$call,$response)
	{
		$this->wsdl=$wsdl;
		$this->header=$header;
		$this->elements=$elements;
		$this->call=$call;
		$this->response=$response;
	}
	public function callSoap()
	{
		$soapClient=new SoapClient($this->wsdl);
		$arrSoapHeader=$this->header;
		if ($arrSoapHeader != null)
		{
			$soapHeader = new SoapHeader($arrSoapHeader["namespace"], $arrSoapHeader["name"], $arrSoapHeader["data"], $arrSoapHeader["understand"]);
		}
		else
		{
			$soapHeader = null;
		}
		$arrSoapElement = $this->elements;
		$SoapReturn = $soapClient->__soapcall($this->call,$prarm1=array($arrSoapElement), null, $soapHeader);
		unset($soapHeader);
		unset($soapClient);
		eval("\$return = \$SoapReturn->".$this->response.";");
		return $return;
	}
}
?>